package ldk.app.kotlinweibo.activities

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.Gravity
import android.view.WindowManager
import dagger.android.AndroidInjection
import io.reactivex.android.schedulers.AndroidSchedulers
import kotlinx.android.synthetic.main.activity_main.*
import ldk.app.kotlinweibo.R
import ldk.app.kotlinweibo.apis.APIErrorCommon
import ldk.app.kotlinweibo.configs.Session
import retrofit2.Retrofit
import javax.inject.Inject

/**
 * Application's main page
 * Created by ldkxingzhe@163.com on 2017/6/16.
 */
class MainActivity : AppCompatActivity(){
    private val TAG = "MainActivity"

    @Inject
    internal lateinit var mSession: Session

    @Inject
    internal lateinit var mRetrofit: Retrofit

    override fun onCreate(savedInstanceState: Bundle?) {
        AndroidInjection.inject(this)
        super.onCreate(savedInstanceState)
        window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
        setContentView(R.layout.activity_main)

        iv_header.setOnClickListener {
            drawer.openDrawer(Gravity.LEFT)
        }
        mSession.currentUser(mRetrofit)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
                        {iv_header.setImageURI(it.profile_image_url)},
                        {APIErrorCommon.toastMessage(this, it.message)})
    }
}